package top.jacktgq.lock.deadLock;

import top.jacktgq.utils.LogUtils;
import top.jacktgq.utils.Sleeper;

/**
 * 
 * @Title: DeadLockDemo.java 
 * @Package top.jacktgq.lock.deadLock 
 * @Description: 两个线程之间的死锁问题
 * @author CandyWall   
 * @date 2020年11月2日 上午1:10:09 
 * @version V1.0
 */
public class DeadLockDemo {
	public static void main(String[] args) {
		Object A = new Object();
		Object B = new Object();
		Thread t1 = new Thread(() -> {
			synchronized (A) {
				LogUtils.log("DeadLockDemo", "lock A");
				Sleeper.sleep(1);
				synchronized (B) {
					LogUtils.log("DeadLockDemo", "lock B");
					LogUtils.log("DeadLockDemo", "操作...");
				}
			}
		}, "t1");
		Thread t2 = new Thread(() -> {
			synchronized (B) {
				LogUtils.log("DeadLockDemo", "lock B");
				Sleeper.sleep(1);
				synchronized (A) {
					LogUtils.log("DeadLockDemo", "lock A");
					LogUtils.log("DeadLockDemo", "操作...");
				}
			}
		}, "t2");
		t1.start();
		t2.start();
	}
}
